package com.hm.jiaowuxitong.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;



import com.hm.jiaowuxitong.util.CustomComboBoxUI;


public class AdministratorGui {
    public static void main(String[] args) {
        new  AdministratorGui();
    }
    public AdministratorGui() {
        JFrame frame = new JFrame("管理员");
        frame.setSize(800, 470);
        //创建画布
        JPanel panel = new JPanel(new BorderLayout());
        //创建方向布局
        SpringLayout layout = new SpringLayout();
        panel.setLayout(layout);

        JLabel label = new JLabel("通知栏");
        label.setForeground(new Color(226,17,17));
        Font font = new Font(label.getFont().getName(), Font.PLAIN, 30);
        label.setFont(font);
        JTextField textField = new JTextField();
        textField.setEditable(false);
        layout.putConstraint(SpringLayout.EAST,textField,-30,SpringLayout.EAST,panel);
        layout.putConstraint(SpringLayout.NORTH,textField,80,SpringLayout.NORTH,panel);
        layout.putConstraint(SpringLayout.NORTH,label,5,SpringLayout.NORTH,panel);
        layout.putConstraint(SpringLayout.EAST,label,-40,SpringLayout.EAST,panel);
        textField.setFont(new Font("", 2, 40));
        textField.setPreferredSize(new Dimension(300,300));
        label.setPreferredSize(new Dimension(200,80));

        JButton button = new JButton("返回");
        layout.putConstraint(SpringLayout.WEST, button, 150, SpringLayout.WEST, panel);
        layout.putConstraint(SpringLayout.NORTH, button, 350, SpringLayout.NORTH, panel);
        button.setFont(new Font(" ", 2, 20));
        JButton button1 = new JButton("进入");
        layout.putConstraint(SpringLayout.WEST, button1, 50, SpringLayout.EAST, button);
        layout.putConstraint(SpringLayout.NORTH, button1, 350, SpringLayout.NORTH, panel);
        button1.setFont(new Font(" ", 2, 20));

        // 创建下拉框模型
        DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
        model.addElement("教师管理"); // 添加标题
        model.addElement("增加教师信息");
        model.addElement("删除教师信息");
        model.addElement("修改教师信息");
        model.addElement("查询教师信息");
        // 创建下拉框
        JComboBox<String> comboBox = new JComboBox<>(model);
        comboBox.setRenderer(new CustomComboBoxRenderer()); // 设置自定义渲染器
        comboBox.setUI(new CustomComboBoxUI());
        // 设置下拉框的位置和大小
        layout.putConstraint(SpringLayout.WEST, comboBox, 25, SpringLayout.WEST, panel);
        layout.putConstraint(SpringLayout.NORTH, comboBox, 25, SpringLayout.NORTH, panel);
        comboBox.setForeground(Color.black);
        comboBox.setPreferredSize(new Dimension(185, 25));
        comboBox.setFont(new Font("",3,25));

        // 创建下拉框模型
        DefaultComboBoxModel<String> model1 = new DefaultComboBoxModel<>();
        model1.addElement("学生管理"); // 添加标题
        model1.addElement("增加学生信息");
        model1.addElement("删除学生信息");
        model1.addElement("修改学生信息");
        model1.addElement("查询学生信息");
        // 创建下拉框
        JComboBox<String> comboBox1 = new JComboBox<>(model1);
        comboBox1.setRenderer(new CustomComboBoxRenderer()); // 设置自定义渲染器
        comboBox1.setUI(new CustomComboBoxUI());
        // 设置下拉框的位置和大小
        layout.putConstraint(SpringLayout.WEST, comboBox1, 30, SpringLayout.EAST, comboBox);
        layout.putConstraint(SpringLayout.NORTH, comboBox1, 25, SpringLayout.NORTH, panel);
        comboBox1.setForeground(Color.black);
        comboBox1.setPreferredSize(new Dimension(185, 25));
        comboBox1.setFont(new Font("",3,25));

        // 创建下拉框模型
        DefaultComboBoxModel<String> model2 = new DefaultComboBoxModel<>();
        model2.addElement("班级管理"); // 添加标题
        model2.addElement("增加班级信息");
        model2.addElement("删除班级信息");
        model2.addElement("修改班级信息");
        model2.addElement("查询班级信息");
        // 创建下拉框
        JComboBox<String> comboBox2 = new JComboBox<>(model2);
        comboBox2.setRenderer(new CustomComboBoxRenderer()); // 设置自定义渲染器

        comboBox2.setUI(new CustomComboBoxUI());
        // 设置下拉框的位置和大小
        layout.putConstraint(SpringLayout.WEST, comboBox2, 25, SpringLayout.WEST, panel);
        layout.putConstraint(SpringLayout.NORTH, comboBox2, 200, SpringLayout.NORTH, comboBox);
        comboBox2.setForeground(Color.black);
        comboBox2.setPreferredSize(new Dimension(185, 25));
        comboBox2.setFont(new Font("",3,25));

        // 创建下拉框模型
        DefaultComboBoxModel<String> model3 = new DefaultComboBoxModel<>();
        model3.addElement("课程管理"); // 添加标题
        model3.addElement("增加课程信息");
        model3.addElement("删除课程信息");
        model3.addElement("修改课程信息");
        model3.addElement("查询课程信息");
        // 创建下拉框
        JComboBox<String> comboBox3 = new JComboBox<>(model3);
        comboBox3.setRenderer(new CustomComboBoxRenderer()); // 设置自定义渲染器

        comboBox3.setUI(new CustomComboBoxUI());
        // 设置下拉框的位置和大小
        layout.putConstraint(SpringLayout.WEST, comboBox3, 30, SpringLayout.EAST, comboBox2);
        layout.putConstraint(SpringLayout.NORTH, comboBox3, 200, SpringLayout.NORTH, comboBox1);
        comboBox3.setForeground(Color.black);
        comboBox3.setPreferredSize(new Dimension(185, 25));
        comboBox3.setFont(new Font("",3,25));


        panel.add(button);
        panel.add(button1);
        panel.add(label);
        panel.add(textField);
        panel.add(comboBox);
        panel.add(comboBox1);
        panel.add(comboBox2);
        panel.add(comboBox3);


        JLabel img = new JLabel();
        ImageIcon imageIcon = new ImageIcon("image/4.jpg");  // 将"path/to/your/image.jpg"替换为你的图片路径
        img.setIcon(imageIcon);
        //把画布添加至面板
        frame.setContentPane(panel);
        //禁止面板放大缩小
        frame.setResizable(false);
        //允许关闭整个应用
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //将面板显示
        frame.setVisible(true);
        // 设置窗口居中显示
        frame.setLocationRelativeTo(null);
        // 显示窗口
        frame.setVisible(true);
        button.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {

            }

            @Override
            public void mousePressed(MouseEvent e) {

                frame.dispose();
                new GifTest();
            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
        button1.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {

            }

            @Override
            public void mousePressed(MouseEvent e) {
                String selectedOption = (String) comboBox.getSelectedItem();
                if (selectedOption.equals("修改教师信息")) {
                    new UpdataTeacherInfoUI();
                    frame.dispose();

                }
                else if(selectedOption.equals("增加教师信息")){
                    new AddTeacherInfoUI();
                    frame.dispose();
                }
                else if(selectedOption.equals("删除教师信息")){
                    new DeleteTeacherInfoUI();
                    frame.dispose();
                }
                else if(selectedOption.equals("查询教师信息")){
                    new ShowTeacherInfoList();
                    frame.dispose();
                }
                String selectedOption1 = (String) comboBox1.getSelectedItem();
                if (selectedOption1.equals("修改学生信息")) {
                    new UpdataStudentInfoUI(0);
                    frame.dispose();

                }
                else if(selectedOption1.equals("增加学生信息")){
                    new AddStudentInfoUI(0);
                    frame.dispose();
                }
                else if(selectedOption1.equals("删除学生信息")){
                    new DeleteStudentInfoUI(0);
                    frame.dispose();
                }
                else if(selectedOption1.equals("查询学生信息")){
                    new ShowStudentInfoList(0);
                    frame.dispose();
                }
                String selectedOption2 = (String) comboBox2.getSelectedItem();
                if (selectedOption2.equals("修改班级信息")) {
                    new DeleteClassInfoUI();
                    frame.dispose();

                }
                else if(selectedOption2.equals("增加班级信息")){
                    new AddClassInfoUI();
                    frame.dispose();
                }
                else if(selectedOption2.equals("删除班级信息")){
                    new DeleteClassInfoUI();
                    frame.dispose();
                }
                else if(selectedOption2.equals("查询班级信息")){
                    new ShowClassInfoList();
                    frame.dispose();
                }
                String selectedOption3 = (String) comboBox3.getSelectedItem();
                if (selectedOption3.equals("修改课程信息")) {
                    new DeleteCourseInfoUI();
                    frame.dispose();

                }
                else if(selectedOption3.equals("增加课程信息")){
                    new AddCourseInfoUI();
                    frame.dispose();
                }
                else if(selectedOption3.equals("删除课程信息")){
                    new DeleteCourseInfoUI();
                    frame.dispose();
                }
                else if(selectedOption3.equals("查询课程信息")){
                    new ShowCourseInfoList();
                    frame.dispose();
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });

    }

    static class CustomComboBoxRenderer extends DefaultListCellRenderer {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

            // 第一个选项无法选择
            if (index == 0) {
                label.setEnabled(false);
            }

            return label;
        }
    }
}